/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    unordered_set<int> se;
    bool f = false;
    int k;

    void dfs(TreeNode* u) {
        if (!u) return;
        dfs(u->left);
        int x = u->val;
        if (se.count(k - x))
            f = true;
        se.insert(x);
        dfs(u->right);
    }

    bool findTarget(TreeNode* root, int _k) {
        k = _k;
        dfs(root);
        return f;
    }
};
